<template>
  <div class="box-line">
    <div class="title">
      <p>游客量趋势图</p>
      <p class="bg"></p>
    </div>
    <div ref="lineChart" class="charts"></div>
  </div>
</template>

<script lang="ts" setup>
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'

const lineChart = ref()

onMounted(() => {
  const myLineChart = echarts.init(lineChart.value)
  // 设置配置项
  myLineChart.setOption({
    title: {
      text: '访问量',
      top: 5,
      textStyle: {
        color: '#fff',
        fontWeight: 100,
        fontSize: 12,
      },
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985',
        },
      },
    },
    // x/y 轴
    xAxis: {
      type: 'category',
      boundaryGap: false, // 图表两边不留白
      // 分割线
      splitLine: {
        show: false,
      },
      // 轴线的设置
      axisLine: {
        show: true,
        // X 轴刻度文字样式
        lineStyle: {
          color: '#fff',
        },
      },
      // 轴线刻度
      axisTick: {
        show: true,
      },
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    },
    yAxis: {
      // 分割线
      splitLine: {
        show: false,
      },
      // 轴线的设置
      axisLine: {
        show: true,
        // Y 轴刻度文字样式
        lineStyle: {
          color: '#fff',
        },
      },
      // 轴线刻度
      axisTick: {
        show: true,
      },
    },
    grid: {
      left: 40,
      top: 30,
      right: 25,
      bottom: 20,
    },
    // 系列
    series: [
      {
        type: 'line',
        data: [120, 834, 345, 456, 967, 678, 789],
        smooth: true, // 平滑曲线
        showSymbol: false, // 定点是否显示
        emphasis: {
          focus: 'series',
        },
        // 区域填充样式
        areaStyle: {
          opacity: 0.8,
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgb(128, 255, 165)',
            },
            {
              offset: 1,
              color: 'rgb(1, 191, 236)',
            },
          ]),
        },
      },
    ],
  })
})
</script>

<style lang="scss" scoped>
.box-line {
  // width: 100%;
  // height: 100%;
  background: url('../../images/dataScreen-main-cb.png') no-repeat;
  background-size: 100% 100%;
  // margin: 0px 20px;
  margin: 0px 20px 20px 20px;
  .title {
    margin-left: 10px;
    p {
      color: white;
      font-size: 20px;
    }
    .bg {
      width: 68px;
      height: 7px;
      background: url('../../images/dataScreen-title.png') no-repeat;
      background-size: 100% 100%;
      margin-top: 10px;
    }
  }
  .charts {
    width: 100%;
    height: calc(100% - 40px);
  }
}
</style>
